
using System.Collections.Generic;
using UnityEngine;
    /// <summary>
    /// Animator Layer扩展
    /// </summary>
    public partial class AbsESF_Animator
    {
        //========================================================================
        #region Layer By Name
        /// <summary>
        /// 获得LayerIndex
        /// </summary>
        /// <param name="_layerIndex">Layer索引</param>
        /// <returns>Layer名称</returns>
        public string GetLayerName(int _layerIndex)
        {
            return animator?.GetLayerName(_layerIndex) ?? string.Empty;
        }
        /// <summary>
        /// 获得LayerIndex
        /// </summary>
        /// <param name="_layerName">Layer名称</param>
        /// <returns>LayerIndex</returns>
        public int GetLayerIndex(string _layerName)
        {
            return animator?.GetLayerIndex(_layerName) ?? -1;
        }
        /// <summary>
        /// 设置Layer权重
        /// </summary>
        /// <param name="_layerName">Layer名称</param>
        /// <param name="_weigth">权重</param>
        /// <returns>weigth</returns>
        public float GetWeigth(string _layerName)
        {
            int idx = GetLayerIndex(_layerName);
            float result = 0;
            if (idx >= 0)
            {
                result = animator?.GetLayerWeight(idx) ?? default;
            }
            return result;
        }
        /// <summary>
        /// 设置Layer权重
        /// </summary>
        /// <param name="_layerName">Layer名称</param>
        /// <param name="_weigth">权重</param>
        public void SetWeigth(string _layerName, float _weigth)
        {
            int idx = GetLayerIndex(_layerName);
            if (idx >= 0)
            {
                animator?.SetLayerWeight(idx, Mathf.Clamp01(_weigth));
            }
        }
        #endregion
        #region Layer By Enum
        readonly static Dictionary<string, enESF_AnimatorControllerLayerNameIndex> mDicNameAnimatorControllerLayerMap = 
            typeof(enESF_AnimatorControllerLayerNameIndex).ESF_NameToEnum<enESF_AnimatorControllerLayerNameIndex>();
        /// <summary>
        /// 获得LayerIndex
        /// </summary>
        /// <param name="_layerIndex">Layer索引</param>
        /// <returns>Layer名称</returns>
        public enESF_AnimatorControllerLayerNameIndex GetLayerEnumName(int _layerIndex)
        {
            enESF_AnimatorControllerLayerNameIndex layer = default;
            string name = GetLayerName(_layerIndex);
            if (!mDicNameAnimatorControllerLayerMap.TryGetValue(name, out layer))
            {
                ESF_P.ESF_Error($"未找到Layer[{_layerIndex}]，将使用{layer}代替");
            }
            return layer;
        }
        /// <summary>
        /// 获得LayerIndex
        /// </summary>
        /// <param name="_layer">Layer</param>
        /// <returns>LayerIndex</returns>
        public int GetLayerIndex(enESF_AnimatorControllerLayerNameIndex _layer)
        {
            return GetLayerIndex(_layer.ToString());
        }
        /// <summary>
        /// 设置Layer权重
        /// </summary>
        /// <param name="_layer">Layer</param>
        /// <param name="_weigth">权重</param>
        /// <returns>weigth</returns>
        public float GetWeigth(enESF_AnimatorControllerLayerNameIndex _layer)
        {
            return GetWeigth(_layer.ToString());
        }
        /// <summary>
        /// 设置Layer权重
        /// </summary>
        /// <param name="_layer">Layer</param>
        /// <param name="_weigth">权重</param>
        public void SetWeigth(enESF_AnimatorControllerLayerNameIndex _layer, float _weigth)
        {
            SetWeigth(_layer.ToString(), _weigth);
        }
        #endregion
        //========================================================================
        
        //=================分隔线===================================================
            #region Base_Layer_0
            /// <summary>
            /// 获得Base_Layer_0索引
            /// </summary>
            /// <returns>Layer索引</returns>
            public int GetLayerIndex_Base_Layer_0()
            {
                return GetLayerIndex(enESF_AnimatorControllerLayerNameIndex.Base_Layer_0);
            }
            /// <summary>
            /// 设置Base_Layer_0权重
            /// </summary>
            /// <param name="_weigth">权重</param>
            /// <returns>权重</returns>
            public float GetWeigth_Base_Layer_0(float _weigth)
            {
                return GetWeigth(enESF_AnimatorControllerLayerNameIndex.Base_Layer_0);
            }
            /// <summary>
            /// 设置Base_Layer_0权重
            /// </summary>
            /// <param name="_weigth">权重</param>
            public void SetWeigth_Base_Layer_0(float _weigth)
            {
                SetWeigth(enESF_AnimatorControllerLayerNameIndex.Base_Layer_0, _weigth);
            }
            #endregion                
        //=================分隔线===================================================  
        
    }